package com.lz.wsy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.lz.wsy.mapper.BrandMapper;
import com.lz.wsy.pojo.Brand;
import com.lz.wsy.service.BrandService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 品牌信息Service实现
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand>
        implements BrandService {

    @Override
    public Brand get(Integer brandId) {
        return baseMapper.selectById(brandId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addAndEdit(Brand brand) {
        //获取登陆用户信息
        /*LoginUser loginuser = SecurityUtil.getLoginuser();
        brand.setCreateUser(loginuser.getUsername());
        brand.setUpdateUser(loginuser.getUsername());*/
        brand.setUpdateTime(new Date());
        if(null == brand.getBrandId()){
            brand.setCreateTime(new Date());
            baseMapper.insert(brand);
        }else {
            baseMapper.updateById(brand);
        }
        return true;
    }

    @Override
    public boolean delBrand(Integer brandId) {
        return SqlHelper.retBool(baseMapper.deleteById(brandId));
    }





}




